<?php

include_once($_SERVER["DOCUMENT_ROOT"]. "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"]. "/include/user/inc.php");

$g_cgival = array();
$g_show = array();
$g_pro = array();

if(! security_check::check_refer())
{
	throw new Exception("来路不明");
}

function check_cgi_pro()
{
	global $g_cgival, $g_show, $g_pro;
	cgi::both($g_cgival['t'],"t","json");
	$g_cgival['t'] = string::un_html($g_cgival['t']);

	cgi::both($g_cgival['h'],"h",0);
	
	cgi::both($g_cgival['s'],"s","");
	$g_cgival['s'] = string::un_html($g_cgival['s']);
	
	
	cgi::both($g_cgival['w'],"w",0);
	
	cgi::both($g_cgival['x'],"x",0);
	
	cgi::both($g_cgival['y'],"y",0);
	
		
	
}


function get_data()
{
	global $g_cgival, $g_show, $g_pro;
	
	
	$user_info = new user_info();
	$is_login = $user_info->is_logined();
	if($is_login)
	{
		$user_detail_info = $user_info->get_cur_user_info();
		
		$uid = $user_detail_info["uid"];
		$user_nickname = $user_detail_info["user_nickname"];
		
		
	}
	else
	{
		
		throw new Exception("未登录");
	}	
	
	$upload = new pic_upload(array());
	$result = $upload->create_user_head_pic($g_cgival['s'],array($g_cgival['w'],$g_cgival['h'],$g_cgival['x'],$g_cgival['y']),$other_size_info=array(50=>"/50/",30=>"/30/"),"header/180/{$uid}");//传入表单图片名
	$g_show["pic_info"] = $result;
	
	$db_user_info = new db_user_info();
	$res = $db_user_info->update_user_info_by_uid($uid,"",$result["pic"]);
	if(!$res)
	{
		throw new Exception("数据库操作失败");
	}
}

 
try
{
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "操作成功";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();


function show_pro()
{
	global $g_cgival, $g_show, $g_pro;
	

	if($g_cgival['cb'])
	{
		header("Location:".$g_cgival['cb']."?pic_source={$g_show["pic_path"]}&pic={$g_show["pic_path1"]}&pic_name={$g_show["pic_name"]}&size={$g_show["size"]}&form_id={$g_show["form_id"]}&error={$g_show["error"]}&errormsg=".urlencode($g_show["errmsg"]));
	}
	else 
	{
		echo output::json($g_cgival["t"], $g_show, $g_cgival["callback"]);
	}
}